﻿#pragma once
#include <memory>
#include <thread>
#include <mutex>
#include <functional>
#include "oatpp-websocket/WebSocket.hpp"
#include "oatpp-websocket/Connector.hpp"
#include "oatpp-websocket/ConnectionHandler.hpp"
#include "oatpp/network/tcp/client/ConnectionProvider.hpp"

class WebsocektClient
	: std::enable_shared_from_this<WebsocektClient>
{
public:
	WebsocektClient();
	virtual ~WebsocektClient();

public:
	void Start();
	void Stop();	

protected:
	void _Connect();
	void _Heart();

protected:
	bool m_run;
	std::mutex  m_write_lock;
	std::thread m_thread_msg;
	std::thread m_thread_heart;
	std::string m_socket_url = "";
	bool m_connected;
	std::mutex  m_socket_lock;
	std::shared_ptr<oatpp::websocket::WebSocket> m_socket;
	std::shared_ptr<oatpp::network::tcp::client::ConnectionProvider> m_connectionProvider;
	std::shared_ptr<oatpp::websocket::Connector> m_connector;
};

typedef std::shared_ptr<WebsocektClient> WebsocektClientPtr;